﻿/**
* Title:"项目";
*
* Description:
*        功能：
*
* Author:Tongwel
*
* Date:2018.6
*
* Modify:
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace DemoSpace
{
    public class PackView :Mediator
    {
        #region 单例
        private static PackView _instance;
        public static PackView Instance
        {
            get {
                if (_instance==null)
                {
                    _instance = new PackView();
                }
                return _instance;
            }
        }
        #endregion

        public int TotalCount = 15;

        public void ShowPack(List<PackModel> models)
        {
            //控制pack无限添加
            while (this.transform.childCount != 0)
            {
                GameObject.DestroyImmediate(this.transform.GetChild(0).gameObject);
            }
            foreach (var item in models)
            {
                GameObject obj = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("PackItem"));
                obj.transform.SetParent(this.transform);
                obj.transform.localPosition = Vector3.one;
                obj.transform.localScale = Vector3.one;
                //实例化packItem
                PackItem packItem = obj.GetComponent<PackItem>();
                packItem.Model = item;
            }
        }

        //对view命名
        public override string Name
        {
            get{return "PackView";}
        }

        //view信息名称的集合
        public override List<string> MsgList
        {
            get{
                List<string> msgList = new List<string>();
                msgList.Add("show");
                return msgList;
            }
        }

        //view接受消息的方法
        public override void Execute(INotifier notifier)
        {
            switch (notifier.msg)
            {
                case "show":
                    List<PackModel> packModelList = (List<PackModel>)notifier.body;
                    //view的发生事件
                    ShowPack(packModelList);
                    break;
                default:
                    break;
            }
        }
    }
}